#include "c3dCamera.h"


c3dCamera::c3dCamera(void)
{
}


c3dCamera::~c3dCamera(void)
{
}

glm::mat4x4 c3dCamera::GetViewMatrix()
{
	mat4x4 m;

	vec3 xaxis, yaxis;
	vec3 zaxis;
	vec4 z = dir - pos;
	zaxis = vec3(z);
	normalize(zaxis);
	xaxis = cross(vec3(up), zaxis);
	normalize(xaxis);
	yaxis = cross(zaxis, xaxis);

	m[0][0] = xaxis.x;
	m[1][0] = xaxis.y;
	m[2][0] = xaxis.z;
	m[3][0] = -1 * dot(xaxis, vec3(pos));

	m[0][1] = yaxis.x;
	m[1][1] = yaxis.y;
	m[2][1] = yaxis.z;
	m[3][1] = -1 * dot(yaxis, vec3(pos));

	m[0][2] = zaxis.x;
	m[1][2] = zaxis.y;
	m[2][2] = zaxis.z;
	m[3][2] = dot(zaxis, vec3(pos));

	m[0][3] = m[1][3] = m[2][3] = 0.0f;
	m[3][3] = 1.0f;
	return m;
}

mat4x4 c3dCamera::Perspective()
{
	mat4x4 res = GetViewMatrix();
	
	////void c3dExFrame::perspective(mat4x4& m, float fovy, float aspect, float zn, float zf)
	////{
	//	float fax = 1.0f / (float)tan(fovy * 0.5f);

	//	c3dSetZero(m);
	//	m[0][0] = (float)(fax / aspect);
	//	m[1][1] = (float)(fax);
	//	m[2][2] = zf / (zf - zn);
	//	m[3][2] = -zn * zf / (zf - zn);
	//	m[2][3] = 1;
	//}
	return res;
}
